package com.fh.test.spring.springmvc.startup;

import com.tul.cusa.common.log.LogTracerFactory;
import com.tul.cusa.common.log.intf.ILogTracer;
import com.tul.cusa.container.jetty.EmbeddedService;

import java.net.UnknownHostException;

/**
 * @author tuliang
 */
public class StartUp {
	/**
	 * 日志
	 */
	private static final ILogTracer TRACER = LogTracerFactory.getTracer(StartUp.class);

	public static void main(String[] args) {
		// 开启服务
		startServer();
	}

	private static void startServer() {
		try {
			int port = 8088;
			EmbeddedService embeddedService = new MyEmbeddedService("0.0.0.0", port);
			embeddedService.setContextPath("/" + "spring-mvc/");
			embeddedService.setResourceBase("spring-mvc-web/dist/");
			String webXmlPath = StartUp.class.getResource("/WEB-INF/web.xml").getPath();
			embeddedService.setDescriptor(webXmlPath);
			embeddedService.setWebAppContextHandler();
			embeddedService.serverStart();
		} catch (Exception e) {
			TRACER.error("启动异常", e);
		}
	}
	/**
	 * 自定义启动
	 */
	static class MyEmbeddedService extends EmbeddedService {
		/**
		 * Constructor.
		 *
		 * @param host ip
		 * @param port port
		 * @throws UnknownHostException UnknownHostException
		 */
		public MyEmbeddedService(String host, int port) throws UnknownHostException {
			super(host, port);
		}

	}
}
